package com.xasz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xasz.entity.Jury;
import com.xasz.service.IJuryService;
import com.xasz.service.impl.JuryServiceImpl;
import com.xasz.util.JsonResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cai
 * @since 2022-07-28
 */
@AllArgsConstructor
@RestController
@RequestMapping("jury")
public class JuryController  extends BaseController{

    private IJuryService iJuryService;
    private JuryServiceImpl juryService;
    /**
     * 增加评委
     */
    @PostMapping
    public JsonResult<Void> inputJury(@RequestBody Jury jury, HttpSession session){
        juryService.addJury(jury,getUidFromSession(session));
        return new JsonResult<>(OK);
    }
    /**
     * 删除评委
     */
    @DeleteMapping
    public  JsonResult<Void>  DeleteJury(@RequestBody Jury jury,HttpSession session){
        juryService.detectJury(jury.getActivityId(),jury.getId(),getUidFromSession(session),getUsernameFromSession(session));
        return new JsonResult<>(OK);
    }
    /**
     * 通过活动id查询有哪些评委
     */
    @GetMapping
    public JsonResult<List<Jury>> getJuryByAid(Integer Aid,HttpSession session){

        return new JsonResult<>(OK,juryService.selectByAid(Aid,getUidFromSession(session)));
    }


    //超级管理员专用查询所有活动的评委
    @GetMapping("super")
    public JsonResult<List<Jury>> getJury(){
        return new JsonResult<>(OK,iJuryService.list());
    }

}
